/**
 * @author YinHang
 */
;(function () {
	var Layer = GameFramework.inherit("ui.g2d.Displayable")(function (width, height) {
		this.visibles = [];
		this.setWidth(width);
		this.setHeight(height);
	});
	
	Layer.prototype.add = function (visible) {
		this.visibles.push(visible);
	};
	
	Layer.prototype.remove = function (index) {
		this.visible[index] = null;
	};
	
	Layer.prototype.getGraphics = function () {
		return this.canvas.graphics;
	};
	
	Layer.prototype.clear = function (color) {
		this.canvas.getGraphics().fillRect(color, 0, 0, this.width, this.height);
	};
	
	Layer.prototype.drawToBuffer = function () {
		var g = this.canvas.getGraphics();
		var visibleLength = this.visibles.length;
		for(var i=0;i<visibleLength;++i)
			if(this.visibles[i] && this.visibles[i].getVisible())
				this.visibles[i].draw(g);
	};
	
	Layer.prototype.draw = function (graphics) {
		this.clear("rgb(255, 255, 255)");
		this.drawToBuffer();
		graphics.drawCanvas(this.canvas, this.x, this.y, this.width, this.height);
	};
	
	GameFramework.register(Layer);
})();
